package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.CategoryAttrBatchInsertRequestDTO;
import com.example.child_protection.dto.request.add.CategoryAttrInsertRequestDTO;
import com.example.child_protection.dto.request.find.CategoryAttrRequestDTO;
import com.example.child_protection.dto.request.update.CategoryAttrUpdateRequestDTO;
import com.example.child_protection.dto.response.CategoryAttrListResponseDTO;
import com.example.child_protection.dto.response.CategoryAttrResponseDTO;
import com.example.child_protection.service.CategoryAttrManageService;
import com.example.child_protection.service.CategoryAttrQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 类目属性管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("categoryAttr")
@Api(value = "/api-categoryAttr", description = "类目属性管理")
public class CategoryAttrController extends BaseController {

    @Autowired
    public CategoryAttrManageService categoryAttrManageService;

    @Autowired
    public CategoryAttrQueryService categoryAttrQueryService;

    @ApiOperation(value ="查询类目属性", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public CategoryAttrResponseDTO findId(SimpleIdRequestDTO requestDTO,HttpServletRequest request)throws Exception{
        CategoryAttrResponseDTO responseDTO = categoryAttrQueryService.findId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询类目属性列表信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public CategoryAttrListResponseDTO findList(CategoryAttrRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        CategoryAttrListResponseDTO responseDTO = categoryAttrQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="保存类目属性（批量）", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insertBatch", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insertBatch(CategoryAttrBatchInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = categoryAttrManageService.insertBatch(requestDTO);
        return responseDTO;
    }
    
    @ApiOperation(value ="添加类目属性", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(CategoryAttrInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = categoryAttrManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改类目属性", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(CategoryAttrUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = categoryAttrManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除类目属性", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = categoryAttrManageService.delete(requestDTO);
        return responseDTO;
    }

}
